WiringPi is now maintained under GIT for ease of change tracking, however there is a Plan B if you’re unable to use GIT for whatever reasons (usually your firewall will be blocking you, so do check that first!)
If you do not have GIT installed, then under any of the Debian releases (e.g. Raspbian), you can install it with:
sudo apt-get install git-core
If you get any errors here, make sure your Pi is up to date with the latest versions of Raspbian:
sudo apt-get update sudo apt-get upgrade
To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi
If you have already used the clone operation for the first time, then
cd wiringPi git pull origin
Will fetch an updated version then you can re-run the build script below.
To build/install there is a new simplified script:
cd wiringPi ./build
The new build script will compile and install it all for you – it does use the sudo command at one point, so you may wish to inspect the script before running it.
Plan B
Click on this URL: (it should open in a new page)
https://git.drogon.net/?p=wiringPi;a=summary
Then look for the link marked snapshot at the right-hand side. You want to click on the top one.
This will download a tar.gz file with a name like wiringPi-98bcb20.tar.gz. Note that the numbers and letters after wiringPi (98bcb20 in this case) will probably be different – they’re a unique identifier for each release.
You then need to do this to install:
tar xfz wiringPi-98bcb20.tar.gz cd wiringPi-98bcb20 ./build
Remmeber the actual filename will be different – you will have to check the name and adjust accordingly.
Test wiringPi’s installation
run the gpio command to check the installation:
gpio -v gpio readall
That should give you some confidence that it’s working OK.
WiringPi is released under the GNU Lesser Public License version 3.
Hi..
The PWM-Test (test2) with a LED between Pin12 and Pin3 (GND) produces weird noises on the sound output jack. Can I solve this somehow ?
No, sorry!
The Pi only has 2 PWM output pins and they’re normally used for the audio output on the 3.5mm jack socket. If you re-program the GPIO pin for PWM, it then uses one of the 2 PWM channels that goes to the audio output – so when you use it to drive an LED or motor, etc. it will make some sort of noise on the audio…
-Gordon
Thank you for your work done with this project. I can now run test2 successfully from command line only. I have a rough idea how to write and compile programs with text editors. (I’ve used Geany as my editor.)
I am teaching my 13 year old daughter with Geany on the Raspi to write basic C++ programs. (I never used Linux for C/C++ before yesterday.) How do I include these libraries into g++ so that I can use Geany to write and test the code? It will be great if we can “do stuff” via GPIO as well. I don’t want to drag out the Arduino as well.
Regards
I really don’t know much about Geany and its environment. All my work is done using a text editor like Vi (or vim), and Makefiles…
I’ll have a look at it if I have some time though.
-Gordon
Thank you for both replies to my questions. I still have a lot to learn, at least I can write with Geany, its just the compiling bit that’s a bummer. I think my question is more general in any case. Basically, how to get extra libraries and headers into C++ with linux. So far I did not had much luck figuring it out.
Regards and thank you once a again for helping me make my own LED pattern go blink blink blink!
What you can do is simply copy the source-code in-line with your own program. Just add it all on at the top of the program. It’s not elegant, but it should work!
I’ve not had time to look at Geany yet though.
-Gordon
Hello Jaques
Like you I use Geany to program, compile and debug C programs and also I had the same problem with wiring library. Here is my solution.
Go to ‘Build’ menu and then ‘Set Build Commands’. In the second option, ‘Build’, you have to write the following:
gcc -o “%e” -l/usr/local/include “%f” -L/usr/local/lib -lwiringPi
I assume that you have followed the standar installation instructions.
Hope this helps.
Regards.
Hello Gordon,
I have just downloaded and perused your WiringPi code.
Looks very interesting. Thanks for making it available as it shows many useful specifics for using the Raspberry Pi’s GPIO.
One thing that I noticed was that in the definition of the pinMode function in wiringPi.c the static flag pwmRunning seems only to be defined and initialised to FALSE and tested and never set to anything else. Should it possibly be set to TRUE somewhere, maybe at the end of the if (!pwmRunning) block? Or have I missed the point?
Regards
Ralph
Looks like you’ve not missed the point, but I’ve missed a line! There should be a pwmRunning = TRUE in that block. However it’s not really doing any harm, just a minor optimisation and I’ll sort it out then next time I do an update!
Thanks!
-Gordon
Could this code be used on my Raspberri Pi? I know it runs on an Arduino to control leds on a reef tank. Thanks
byte MoonPhase()
{
int m,d,y;
int yy,mm;
long K1,K2,K3,J,V;
byte PWMvalue;
m = month();
d = day();
y = year();
yy = y-((12-m)/10);
mm = m+9;
if (mm>=12) mm -= 12;
K1 = 365.25*(yy+4712);
K2 = 30.6*mm+.5;
K3 = int(int((yy/100)+49)*.75)-38;
J = K1+K2+d+59-K3;
V = (J-2451550.1)/0.29530588853;
V -= int(V/100)*100;
V = abs(V-50);
PWMvalue = 4*abs(50-V); // 5.12=100% 4=~80%
//pinMode(lowATOPin,OUTPUT);
return (PWMvalue*100)/255;
}
It returns 0-100.
You can comment the kast line and return PWMvalue for 0-255.
Essentially yes.
You may have to tweak a few things though – e.g. there might not be a “byte” type (and even on the arduino, you probably want to #include <stdint.h> and use uint8_t instead of ‘byte’…)
The PWM value is 0 to 1023, so might need a little scaling.
ints on the Pi are signed 32-bit values, as are longs, so do check ranges and so on.
Not sure where you’re getting the day(), month() and year() functions from either, but I’ll assume you have something else to provide them… If not, and you’re not sure how to do this stuff under unix then lookup the manual page for the ctime() function.
-Gordon
I tried to cc the code and got this error.
It also did not like the stdint.h
lunar.c:1:1: error: unknown type name ‘unit8_t’
lunar.c: In function ‘MoonPhase’:
lunar.c:7:1: error: unknown type name ‘unit8_t’
lunar.c:16:6: error: expected expression before ‘int’
lunar.c:19:6: error: expected expression before ‘int’
uint8_t is defined in stdint.h – it’s surprising if your system doesn’t have stdint.h though.
#include <stdint.h>
?
-Gordon
This is a response to a really old thread but I think the coding error is because you typed in ‘unit8_t’ and it should be ‘uint8_t’.
Ah… I’m a shade dyslexic and often don’t see things like that myself…
-Gordon
Sometimes I’m dylsexic too!
Gordon – have recently downloaded this update with added serial commands. I’m very new to all this and wondered if you could help? I’ve written some midi code for the Arduino (which all works fine)based on the Arduino midi example:
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}
void loop() {
// play notes from F#-0 (0x1E) to F#-5 (0x5A):
for (int note = 0x1E; note < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
I've tried to adapt this using your serial library but I just can't work it out – if you, or someone else who reads this, wouldn't mind could you adapt the above code so it will run on raspberry pi – once I have that I think I can work on it from there.
Thanks for your help
ok. A very quick translation:
Serial.begin (baud) becomes fd = serialOpen (“/dev/ttyAMA0”, 31250) ;
However sadly this will fail as that’s not a recognised baud rate in the Linux world.
So if you can change the baud rates then it’ll work, otherwise I don’t know where to start, but a quick google suggests this may help you: http://joost.damad.be/2009/05/how-to-set-serial-port-at-midi-speed-in.html
in your noteOn() function:
Serial.write (val) becomes serialPutchar (fd, val) ;
And that’s it at it’s simplest. the ‘fd’ value (and int) is the file descriptor (everything is a file in unix land). You just need to make that avalable to any code that wants to use the serial port. (maybe a global for you). The /dev/ttyAMA0 is the on-board serial port (3.3v, remember). However it could be a USB serial port – e.g. /dev/ttyUSB0 for example…
-Gordon
Hello Gordon,
“However it could be a USB serial port – e.g. /dev/ttyUSB0 for example…”
With device “/dev/ttyAMA0″ and a MAX3232 it works nice. Your second suggestion sending serial data to USB sounds interesting. Anyway, i do not have a /dev/ttyUSB0” in my /dev/ folder. May you explain how to do this ?
thanks wally
You’ll only see a /dev/ttyUSB0 if you plug in a USB serial device.
The Pi’s on-board serial port is /dev/ttyAMA0.
In Linux all serial ports work more or less the same – they just have different names – /dev/ttyAMA0 for the on-board on one a Pi, /dev/ttyS0 for the on-board one on a typical PC, /dev/ttyUSB0 for usb serial devices (ftdi), and /dev/ttyACM0 for some other modem devices (sometimes 3G modems)
-Gordon
“You’ll only see a /dev/ttyUSB0 if you plug in a USB serial device.”
sure, i’m donkey 🙂
thank you
Nah, but it’s easy to get confused if you’re new to all this!
-Gordon
I seem to be stuck already. Am I ok doing this in lx terminal or should i be elsewhere, the files are in the examples folder
pi@raspberrypi:/tmp/wiringPi/examples$ sudo ./test1
sudo: ./test1: command not found
pi@raspberrypi:/tmp/wiringPi/examples$ sudo ./test2
sudo: ./test2: command not found
thanks
JG
lxterm is fine.
did you do the sequence of:
cd wiringPi/wiringPi
make
sudo make install
cd ../ gpio
make
sudo make install
— and finally:
cd ../examples
make <--- did you type make? sudo ./test1 I'm wondering if you missed out the 'make' command in the examples directory. However, unless you connect up some LEDs to the Pi, you're not going to see very much happening - they are really intended to be used as examples to base your own GPIO programs on. -Gordon
sorry. missed out a line
thanks
JG
Ah, guesed you missed the final ‘make’ them. Do look at the programs though and if you want more examples, there are a few more on my website – e.g. lookup the TuxX program and the ladders game …
-Gordon
Have just tried to install following your guidelines but ran into a problem:
pi@raspberrypi /tmp $ tar xfz wiringPi.tgz
pi@raspberrypi /tmp $ cd wiringPi/wiringPi
pi@raspberrypi /tmp/wiringPi/wiringPi $ make
[CC] wiringPi.c
[CC] serial.c
[CC] wiringShift.c
[CC] lcd.c
[CC] piHiPri.c
[CC] piThread.c
[AR] wiringPi.o serial.o wiringShift.o lcd.o piHiPri.o piThread.o
make: avr-ar: Command not found
make: *** [libwiringPi.a] Error 127
pi@raspberrypi /tmp/wiringPi/wiringPi $
Got round the problem by using a Makefile from a download yesterday. The fix was:
$(TARGET): $(OBJ)
@echo [AR] $(OBJ)
@ar rcs $(TARGET) $(OBJ)
@size $(TARGET)
Aargh )-:
bother.
That’s what I get for working on some ATmega and Pi projects at the same time. I’ve put the wrong thing in the wrong makefile – (and it happens I have the arduino IDE installed on my Pi’s so I never noticed it).
Thanks for that. I’ll fix it right away.
-Gordon
I get an error when trying to ‘make’: http://i45.photobucket.com/albums/f87/Stew2000/RaspberryPi/DSCF0383-2.jpg
Yes. I’ve goofed on the Makefile. Will fix it right away.
-Gordon
Hi Gordon and thank you for your library. Is it possible to stop the program after I started it?
Type Control-C in the terminal window you started the program in.
(That’s the usual unix/linux way!)
-Gordon
I just wanted to let you know that I have prepared and inserted this into the Arch Linux ARM repos.
Thanks!
What I’m aiming to do is to move it all to GIT, but that requires learning GIT first – I just need to sit down for an afternoon with no interruptions and get on with it..
-Gordon
Hi Gordon
I’ve downloaded and run the install for wiringPi and this completed all ok. Trouble is I can’t seem to compile my own test app, what I did is this:
#include
#include
#include
#include
int main()
{
if(wiringPiSetup() == -1)
exit(1);
else
printf(“wiringPi library ok!”);
return(0);
}
and what i get is “undefined reference to ‘wiringPiSetup’ and a failed compilation.
What do i need to do to get this to compile? BTW: this is both using the gcc command line and geany, both give the same error!
Help!! Thanks in advance! Dan
Try:
cc -o test test.c -lwiringPi
to compile it (assuming your file is called test.c!)
then
sudo ./test
to run it.
I’m not sure about using geany – I don’t use it myself, but I might have to start to have a look soon to work out how to make it use additional libraries.
-Gordon
Many thanks Gordon, much much appreciated! I’ll be sure to let you know how I get on and if I manage to get it to compile under Geany.
Thanks again 🙂
Dan
Dear Gordon,
Thanks for great stuff!
I use the pi as small server and ‘case fan speed contoller’. Your library is really easy to use for beginner like me.
The fan doesn’t accept high frequency pwm wave form (up to 30KHz). so I changed ‘wiringPi.c’ as follows.
in function ‘pinModeGpio’
*(pwm + PWM0_RANGE) = 600/ ; // new
*(pwm + PWM0_DATA) = ;
*(pwm + PWM_CONTROL) = PWM0_ENABLE | PWM1_ENABLE | PWM0_MS_MODE | PWM1_MS_MODE;
Regards
Yes – you’re putting the PWM into the other mode (which is possibly more sensible than the default which is balanced out, but who knows) – it’s something I’ll be doing for the next release, providing the ability to change the frequency and mode.
Cheers,
-Gordon
Hi. Great site, great posts. Due to simplicity of the rpi(Raspberry Pi) I am a recent convert and devotee of the Raspberry Pi and I have a bunch of things to do with it. Can i do the following:
1. Connect 4 rpi and run them in parallel, like multi-threading. I would like them to run one application and give me feed back on different screens. and How can I achieve this.
2. Connect LCD screens to the rpi’s.
3. Use regular DC batteries to power them?
It would be great to hear from you.
Thanks
You’ve just sent me an email which I’ll answer shortly, but briefly:
1 – In theory yes. There are various setups and libraries to do this – e.g. The Beowolf project and so on, or just by writing your own communication mechanisms.
2 – The on-board LCD display port doesn’t have any drivers yet, so right now we’re limited to the HDMI or composite video output
3 – You can power a Pi from batteries, but you’ll need a 5V regulator and be aware that the Pi is going to comsume some 3 watts, so regulat AA’s won’t last long, you’ll need something bigger.
-Gordon
Thanks for this excellent library. Despite being Linux noob and not having done C programming since high school (at which time it was at the hello-world level), I managed to adapt it to servo-motor control. Just increase the period to 12000 (0x2EE0 – giving 50hz), use MS mode as koma did for his fan speed control, and modify the pwm_write routines to allow higher values than 1023 (400 to 1400 would be a suitable range for most servos – I decided to allow up to 4095 to allow for experimenting). Oh, and do not supply power to your servo-motor from the Raspi, even if said servo is small; it *will* lead to crashes.
Which brings me to the point of this post: I don’t think you should recommend building the library in the /tmp folder, or if you do, warn people to copy it elsewhere before starting to modify the source. The reason? Guess what folder is amongst those “cleaned up” as a matter of housekeeping routine when the Raspi starts 😀
—
Best regards, Kári.
Glad your able to use it and modify it – but you’re probably right about /tmp, however you did learn something new 😉
-Gordon
Do you use version control while writing your code? Is this project available on github?
I do use version control – it’s something I put together for myself some 20 years ago based on rcs and really not fit for public consumption… However I’m getting to grips with GIT and will be hosting it on my own servers shortly with gitweb as the front-end (same front-end as the Linux kernel uses)
-Gordon
Hey Mr. Gordon,
Thanks for the additional libraries to wiringPi again, its so exciting to check site for new additional functions, this Serial library will be so helpful to me
Then, when i tried to install again it gives error for /gpio section as :
gpio.c : In function main
gpio.c:555:5 warning: implicit declaration of function ‘wiringPiSetupPiFaceForGpioProg’
gpio.c: error: ‘WPI_MODE_PIFACE’ undeclared (first use in this function)
etc. So as a result i could not build the library
I wonder if i am the only one suffering from the problem, which parts/codes should i remove to sucecsfully build it?
Thanks in advance a lot,
Cheers
Hi,
How did you download and install it?
If you try this:
git clone git://git.drogon.net/wiringPi
then:
cd wiringPi/wiringPi
make
sudo make install
cd ../ gpio
make
sudo make install
then that should make everything cleanly.
Let me know how you get on with that.
-Gordon
i simply follow instructions on the article above, so i use wget to download and then other steps…
It gives error for piFace code actually, i don’t know wheter i am downloading properly or something to do with my own RPi.
Then when i use git clone commands, it says
bash:git: command not found
error.
Could i please also learn how to use git command from LXTerminal so?
Thank you.
OK. If you’re running Debian (Squeeze/Wheezy/Raspbian), then
sudo apt-get install git-core
will fetch and install GIT for you. It may be that the old release files are somewhat incomplete though – probably my fault when moving the project into GIT, so I’ve just pushed the current version to the old downloads site, so try again, either way and let me know how you get on.
-Gordon
Why is nothing in the /wiringPi/examples/ directory executable? Are these complete programs that need to be recompiled?
I thought I was pretty computer savvy but the Rpi code out there is making me feel like an idiot. And there is some bad info on the web, which only makes things worse.
Please, someone out there tell me, from start to finish, what do I need to do to blink an LED on GPIO 21.
I have installed the example programs
You need to make the programs. Just type ‘make’ in the examples programs to build them.
For a start from LED 1 type example, have a look at:
https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/
Do drop me an email though if you need more help to get going.
-Gordon
adding Git (whatever that is) to my Pi ate up 13.8 MB of space.
I’m trying to SAVE space on the SD card… but I dont pretend to understand all of this anyway.
What was wrong with apt-get or aptitude? Can i remove Git now that I’ve installed wiringPi?
Thank you
It’s a good question – and one reason is that while I’ve been using Debian for 18 years, I’m relatively new to actually building packages for it, so it’s on the cards, but not yet.
Also, the GIT way will work on other Linux releases too – e.g. Arch which seems to have a small, but growing community, so GIT makes it an easy way to distribute for everyone.
However, yes, you can remote git –
sudo apt-get purge git-core
sudo apt-get clean
However, you’ll need it again, should you need to upgrade wiringPi.
-Gordon
Well you rock, Sir.
You have a great body of work here. Very helpful. I’ve spent a lot of time wandering the pages here.
Thank you!
Hi,
Im trying to connect a DS18B20 to my pi, and have successfully done so. But I have a problem with timings. I use your lib in the code. Do u know how to make the program faster? I have to have precise timings about 6us. Is there a way to isolate the .c program?
When running in terminal mode I get the fastest pwm high/low within a 336us period and that is to long, want to short it to at lest 15us.
I would like that this sensor worked within the latest debian distro, or is this impossible? Do I have to run the program under other “faster” linux?
If you pull the latest wiringPi via GIT then the delayMicroseconds() code uses a hardware timer when asking to delay under 100uS, then you can bit-bang the interface.
However, there is a kernel module for 1-wire – I’ve not used it myself yet, but it’s there… However, even with the new delayMicroseconds() code, I’d be concerned about latency due to Linux getting in the way. Run as root, call wiringPiSetup() first, then piHiPri (50) ;
Good luck!
-Gordon
Nice work, Gordon!
I took the liberty to change your gpio.c code to make “write” accept any number of pins and values setting them all in one call. E.g.
gpio write 0 1 1 1 2 0 3 0
turns on pins 0 and 1, and turns of pins 2 and 3.
This is my patch:
============================
— gpio.orig.c 2012-09-09 17:50:03.791177105 +0200
+++ gpio.mla.c 2012-09-09 17:56:42.654686200 +0200
@@ -607,25 +607,26 @@
static void doWrite (int argc, char *argv [])
{
– int pin, val ;
+ int ix;
– if (argc != 4)
+ if (argc < 4 || argc % 2)
{
– fprintf (stderr, "Usage: %s write pin value\n", argv [0]) ;
+ fprintf (stderr, "Usage: %s write pin value [ pin value … ]\n", argv [0]) ;
exit (1) ;
}
– pin = atoi (argv [2]) ;
+ for (ix = 2; ix < argc; ix += 2) {
+ int pin, val;
– if ((wpMode == WPI_MODE_PINS) && ((pin = NUM_PINS)))
– return ;
+ pin = atoi(argv[ix]);
– val = atoi (argv [3]) ;
+ if ((wpMode == WPI_MODE_PINS) && ((pin = NUM_PINS)))
+ return ;
– /**/ if (val == 0)
– digitalWrite (pin, LOW) ;
– else
– digitalWrite (pin, HIGH) ;
+ val = atoi(argv[ix + 1]);
+
+ digitalWrite (pin, val ? HIGH : LOW) ;
+ }
}
==================================
Naturally, you do with it what you please!
Cheers!
fischelbyxa
I’ll have a look at it. Thanks!
-Gordon
Aw, this was an incredibly good post. Taking the time and actual effort to make a good
article but what can I say I hesitate a lot and don’t seem to get anything done.
Hello Gordon,
for using wiringPi with gambas i need shared library.
May you show us, how to modify the build-script and/or Makefile
so it creates a shared library additionally ?
wally
Going to have to learn how to do that myself first, but it’s on the to-do list!
-Gordon
Hello Gordon,
maybe this is interesting for winringPi shared lib build.
i uses it and it works.
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=6182&hilit=gambas3
by g4eml » Sat Aug 11, 2012 9:57 pm
Unfortunately Gambas3’s external function definition won’t work with a .a library. It needs a shared object .so library instead.
Not expecting it to work I ran the command
‘ gcc -shared -o libwiringPi.so *.o ‘
in the wiringPi source directory. To my surprise it produced a .so file with no errors displayed.
The file produced is here:- http://www.filedropper.com/libwiringpi
When this was used in a this Gambas test project http://www.filedropper.com/gpiotest it worked as expected.
Have sent you an email – but for anyone else reading, I’m testing a new Makefile which generates both a static and shared library for wiringPi and it’s ancilliary functions.
-Gordon
Hello Gordon,
thanks for getting this nice library on the Pi!
I have just connected an older 2×20 Seiko LCD (L2432)andit essentially works.
But when I run the lcd example it works a while and then suddenly writes random character into the display. Currently no idea what goes wrong. Could this be a timing issue?
-Florian
It could be timing. How old if your wiringPi? But check the file lcd.c in the wiringPi directory – look for delayMicroseconds () – if both calls are 50 then it’s new, but if not then make both numbers 50 – if they already are 50 then try to increase it to 75 to see if it helps.
-Gordon
Hurra – Yes it was timing. I had to increase the delays in the strobe function to 50 and 150. Then it worked. B.t.w. the display is a 2×24. Had to change the validation in lcd.c.
thanks a lot for your tip!
OK. I’ll look into i again. Odd though – the data sheets for those chips all specify the timings in the nano seconds range!
And it seems that the differnet displays have differnet ways to address len x hight.
More to investigate…
-Gordon
Hello Gordon,
I’m little confused yesterday,, i compiled some little test program in your Demo direktori of WiringPi. I got Raspberry PI device. I just wondering, why it is okey if i compile the test.c file with command cc -o test test1.c -lwiringPi? but got error if i compile the source with command “gcc test1.c -o test1”? any answer about my problem?? Thanks
-Naito
With the latest wiringPi release, you compile the examples separately. e.g.
make test2
However… the difference between cc and gcc … Or is it simply because you omitted the -lwiringPi from the 2nd one? Can you post the output?
-Gordon
My 512MB board has the Revision “000f”, but gpio won’t recognize that it’s a hex number and interpret it as 0, not 15.
Well that’s new )-:
I’ll see if I can get some more answers.
-Gordon
Excuse me, I tried the git command in my Pi, but got time out problem while connecting to git.drogon.net. I download the file listed, but it is not the newest one and cannot find the SPI function… Thank you!
Error message are always useful here. Try to ping git.drogon.net and see if https://git.drogon.net/ works too. However I’d try the git commands again – just in-case there was some internet routing issues along the way.
cd
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
-Gordon
Dear Gordan:
Thank you very much. I ping the git.drogon.net and all the data lost. But I can visit the https://git.drogon.net. In this case, how can I install the software? I am afraid it is the firewall in my institute block the link. May I do the manual clone? Thank you very much.
If you use the https://git.drogon.net/ site, then browse to a project, then click on the “snapshot” link on the right, you’ll then get a tar.gz file to download which you can manually unpack.
-Gordon
Hi Gordon,
I’ve a problem with the last version of wiringPi and gpio.
When I try to execute a simple command like “gpio write 0 1” I have an error :
“gpio: error while loading shared libraries: libwiringPi.so.1: cannot open shared object file: No such file or directory”
but in my /usr/local/lib/ I have those files :
# ls -l
total 36
lrwxrwxrwx 1 root root 33 Oct 27 23:26 libwiringPi.so -> /usr/local/lib/libwiringPi.so.1.0
lrwxrwxrwx 1 root root 33 Oct 27 23:26 libwiringPi.so.1 -> /usr/local/lib/libwiringPi.so.1.0
-rwxr-xr-x 1 root root 32951 Oct 27 23:26 libwiringPi.so.1.0
…
Any idea ?
(sorry for my english, I’m french ^^”)
Sorry, it’s me again ! xD
I’ve found a very simple solution
echo “/usr/local/lib/” >> /etc/ld.so.conf/d/gpio.conf
ldconfig
That’s all, for information I’m running ArchLinuw on my Raspberry Pi and apparently, Arch by default don’t seek on /usr/local/lib for shard object…
that’s weird
Ah, Arch Linux. I do all my devleopment on Debian (Raspbian) and it has /usr/local/lib in /etc/ld.so.conf.d/libc.conf by default.
I’ll need to investigate some way round that one (although putting it in /usr/lib might be the way round it!)
Thanks,
-Gordon
I haven’t try but it should work if you put the lib in /usr/lib, that’s where I’ve all the .so files
Or, I think you can modify your makefile to add /usr/local/lib in ld.so.conf during the install process, so it will works with any GNU/Linux distros, even with the oddest one 😀
You’re using Arch, I guess?
I’ll have a look … moving from a static library to dynamic has caused more issues that any other change to wiringPi )-:
-Gordon
Thanks very much for this library. I especially like the sys mode for those of us with a nervous disposition (thus reluctant to run everything via sudo!). Via swig I managed to get lua bindings for wiringPi but I had to make a couple of small alterations to wiringpi.i. I also thought that for the sys mode it would be useful to be able to know what direction the pins were set in so wrote that into the code for wiringPi.c. wpiToGpio (is that the right name?) also looked useful but wasn’t available so I fixed that. Let me know if any of these would be useful to you (I have a git repository of my changes). Via lua, I managed to control the pins from within a TeX document, but I’ll be amazed if anyone finds that useful!
Well I use LaTeX for some of my own documentation, but controlling GPIO via TeX – that’s “special” 😉
Drop me an email with your changes and I’ll have a look and see what’ swhat.
-Gordon
So I got the wiringpi installed and everything works perfectly from the console. But when I use the gpio command in a shell script and start it with update-rc.d, it looks like the command is not executed.
Any idea ?
What I know:
* script is really running
* no other program is using gpio
* when I run the script manually it always works
* the same script written in python also does not work when started automatically
my greatest wish right now:
#!/bin/sh
gpio -g mode 7 out
gpio -g write 7 0 #set port 7 to 0V
Maybe double-check that it really is working by using the gpio -v command which will dump some text on the console (if you have a console going!)
But also make sure you’re looking at the right pin – pin 7 (-g) is one of the SPI pins. If the SPI driver is loaded, it might be pulling that pin high.
-Gordon
Thanks for the fast answer 🙂
When calling the script from the console output.txt contains some infos about the wiringpi.
After reboot the file is created but contains nothing.
Using the SPI port or using another port does not matter.
Any new ideas?
new script:
#!/bin/sh
gpio -v > /srv/scripts/output.txt
gpio -g mode 17 out
gpio -g write 17 0
How is the LED wired up?
If you go: GPIO -> Resistor -> LED -> 3.3v then the LED will light when you write 0. Try writing 1 to see if it goes off…
Normally, I’d wire an LED like: GPIO -> Resistor -> LED -> 0v
(Resistor and LED are interchangable)
-Gordon
Everything works fine from the commandline, but when I start the script on bootup via update-rc.d the port is floating and the file mentioned in the post before contains nothing.
Sorry if I myself unclear.
I can’t think why it might not be starting – I’d go through the scripts again, making sure the paths are set right, etc. I can’t think any other reasons right now, sorry..
-Gordon
Hey all.
I’m still trying to get (understand, grasp, comprehend) what I need to do to get the RPi to read data from the ADXL34 3-axis accelerometer. I would be happy if i could call some command line function to get a reading or await interrupts or something.
I’m not smart enough to figure out the few examples I’ve found.
Does someone have a COMPLETE, idiot’s guide to making this happen?
I have no idea if I should use SPI or I2C and there appear to be no wiring schematics in any but one example.
So please, anyone… the world needs a COMPLETE solution for stupid people like me.
0. What am I to expect? is this a command line program or just a library example?? Is this a logging function or will I see something on my screen when I tap the module?
1. Wiring diagram – seriously – Its not even funny, how many “examples” are out there where the schematic was thought of as unnecessary.
2. What do I need installed for the way its wired?
3. What do I do if something doesn’t work?
4. Perhaps EXPLAIN a little about why each of the previous steps was performed. Not everyone knows linux that well.
Thank you very much
You can use Either I2C or SPI with this device. Personally, I’d use SPI, but if you’re more familairwith I2C, then use that.
In either mode, you essentially send the device a read or write command, then specify the internal register to read/write, then you write the data, or read the value of that register. These are all 8-bit commands, so you exchange 2 bytes each cycle.
Then you need to work out the register details, and so on…
It’s not a device I’ve used myself – If you want more replies then you might be better off posting this on one of the Raspberry Pi forums though – or even looking through the Arduino ones too – as Sparkfun make a breakout board for this device, so there will probably be plenty of people using it there…
-Gordon
I’ve really been able to follow your examples on the led. I am a complete noob to this .. so I got this nokia display for $10 and I found
code to drive it.. from the pi .. but the display back light I want to turn on and off .. I can permanently power it off the 3.3 line .. so I thought that I could
1) my gpio is version 1.4 installed a day ago
2) from what I could see I need a switching transistor .. I am using a 2N3906
3) gpio -g mode 18 pwm
at this point the screen goes blank..
my question
1) why the switching transistor.. why can’t I just turn on and off the leds like I did in your experiment? using gpio17 ?
2) I found a document
or the 22N3906 …
R1 = Supply Voltage / ( Maximum Current Required / Minimum HFE * 1.3 )
R1 = 3.3 / (.1 / 100 * 1.3)
2538 so a 2k ohm resistor ?
http://www.rason.org/Projects/transwit/transwit.htm
would that make a difference ??
any guidance would be appreciated ..
the important thing is to find out what the voltage and current rating the back-light needs. If it’s a simple LED or 2, then you might be able to drive it directly from the Pi (via a suitable resistor).
The switching transistor might be needed to drive the backlight at a higher voltage and/or current than the Pi can provide – without knowing the characteristics of the display, I don’t know if it’s needed or not.
I’d also start by not using PWM. So try:
gpio mode 1 out
gpio write 1 0
gpio write 1 1
and see what happens.
-Gordon
Hello Gordon,
I have problem with install your wiringPi library.
when i execute instruction ./build i receive message:
WiringPi library
./build: line 29: make: command not found
sudo: make: command not found
Can You explain me what i do wrong?
PS I USE RASPBMC distribution and g++ compiler.
Best regards
Andrew
It looks like the ‘make’ command isn’t installed with raspbmc. It’s a distribuition I’m not that familair with, but if it’s based on Raspbian (which I think it is), then try this:
sudo apt-get insall make
then re-run the build script.
-Gordon
I ran into the same problem on Raspbmc. This worked:
sudo apt-get update
sudo apt-get install make
sudo apt-get install gcc
Then ./build
Hi Grodon,
Trying to use wiringPi from Eclipse. I immediately ran into problems linking to it. So I studied your make file for the examples. There is a section there:
==========================================================
#DEBUG = -g -O0
DEBUG = -O3
CC = gcc
INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L/usr/local/lib
LIBS = -lwiringPi
===========================================
What I do not understand is the library reference “LIBS = -lwiringPi”. Where does compiler find this wiringPi library?
It is definitely not in /usr/local/lib where you install the shared shared library. Even the shared library name is not the same there (libwiringPi but not wiringPi as in the LIBS declaration).
So where does the compiler find this mysterious “wiringPi” to link to?
Best regards
TJ
-lwiringPi causes the C compiler to look for libwiringPi. where is .a for a static library or .so for the dynamic ones…
So there should be /usr/local/lib/libwiringPi.so as well as some symbolic links to it to represent the versions of that library.
gordon @ pi0: ls -l /usr/local/lib
total 48
lrwxrwxrwx 1 root staff 33 Oct 21 18:53 libwiringPi.so -> /usr/local/lib/libwiringPi.so.1.0
lrwxrwxrwx 1 root staff 33 Oct 21 18:53 libwiringPi.so.1 -> /usr/local/lib/libwiringPi.so.1.0
-rwxr-xr-x 1 root staff 33532 Oct 21 18:53 libwiringPi.so.1.0
I’m now wondering what distro you are using? I know that Debian includes /usr/local/lib in the library search paths by default, but so others?
-Gordon
Aha I was not aware that all libraries in Linux are pre-pended with “lib” (wonder why). As I’m doing cross compiling from Windows Eclipse I copied the /usr/local/lib/libwiringPi.so.1.0 to the lib-path of the Cygwin crosscompiler for RPi and simply renamed it to libwiringPi.so. And acadabra the app linked successfully.
So to fully understand this, why are you installing the libwiringPi.so with a version number appended and then creatig links to that?
The lib prefix is a bit of history that goes back over 30 years (I don’t know why) as for the version numbers – to be honest I did it that way because it seems that’s how everyone else does it – this is the first time I’ve actualyl built a dynamic library for Linux…
Hiny, tips, suggestions for improvement are welcome 😉
-Gordon
Hi Gordon,
I get the following when I run gpio:
Unable to determine board revision from 0
(uname -a = Linux custard 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux) This is a 512MB Made in China RPi deliver a few weeks ago.
Nick
Make sure you’ve got the latest version of wiringPi from GIT.
cd
it clone git://git.drogon.net/wiringPi
cd wiringPi
./build
It sounds like your SoC hasn’t bee properly programmed though – check the output of
cat /proc/cpuinfo
but later versions of wiringPi cater for this (by assuming Rev 2)
-Gordon
Bug discovered in wiringPi/wiringPi.c:
529: (void)*(pwm + PWM_CONTROL) ;
530: while ((*(pwm + PWM_CONTROL) & 0x80) != 0) // Wait for clock to be !BUSY
Obvious writing mistake. Code don’t match the goal described by comment.
Should be corrected to “clk + PWMCLK_CNTL”?
You’re probably right and I’ve gone over the whole of the PWM code – again. Personally, I think the Pi’s PWM hardware is just a bit of a waste of time and have reverted to my software PWM for everything now.
-Gordon
Thank you very much for the explanation. I’m new to linux so sorry in advance for the basic questions. I managed to get the examples to run on my RPi. I have two questions to ask:
1) how can i write my own C++ program and make them compile with your library? is there a special program I need?
2) I’m working on a robotic project, how can i make a specific program run automatically when the raspberry pi is connected to the power?
Thanks
c++ is fine – just #include <wiringPih> as usual and us ethe functions as you would in a C program.
To run a program at boot time – look into /etc/rc.local – you can add it in there. (Raspbian – Arch may be different)
-Gordon
Hi Gordon,
I followed the install instructions above and everything seemed to work fine. I wanted to use wiringPi to geht those easy commands for switching the GPIO outputs. But when I use e.g.:
gpio mode 1 out
gpio write 1 1
the attached light won’t switch on (and no error message is shown). When I use
echo “1″ > /sys/class/gpio/export
echo “out” > /sys/class/gpio/gpio1/direction
echo “1″ > /sys/class/gpio/gpio1/value
The light is perfectly switching on (and off if “0”).
What did I do wrong?
Many thanks in advance and best regards
The issue is confusing the wiringPi numbering scheme with the native chip GPIO numbering scheme.
So using the /sys/class/gpio interface – you’ve exported pin 1 – this is BCM_GPIO 1 – Which on a Rev 1 board is one of the I2C pins. (On a Rev 2 board, it’s not brought out to the edge connector).
So to use the gpio command with that numbering scheme, use the -g flag.
gpio -g mode 1 out
gpio -g write 1 1
and so on.
-Gordon
Thanks! Seems to work.
I was not having any luck compiling the okLed example.
Typing make okLed in the wiringPi directory results in
make: *** No rule to make target `okLed’. Stop.
cd’ing into examples/ and typing make okLed results in:
[link]
/usr/local/lib/libwiringPi.a(piThread.o): In function `piThreadCreate’:
piThread.c:(.text+0x18): undefined reference to `pthread_create’
collect2: ld returned 1 exit status
make: *** [okLed] Error 1
Any idea what I am doing wrong?
You’re doing OK – I goofed when I re-introduced the static libraries. Change the Makefile and add in -lpthread to the LIBS line. I’ll be releasing the fix soon.
-Gordon
Hi Gordon,
Thanks for your efforts in creating/supporting the wiringPi library, much appreciated!
I’ve done a fresh Raspbian (2012-12-16) install on my 256MB model B. Followed the instructions, cloned the git repository. Some of the examples won’t build though (cd examples; make $EXAMPLE):
[CC] tone.c
tone.c: In function ‘main’:
tone.c:17:8: warning: unused variable ‘buf’ [-Wunused-variable]
tone.c:16:10: warning: unused variable ‘j’ [-Wunused-variable]
[link]
/usr/local/lib/libwiringPi.a(piThread.o): In function `piThreadCreate’:
piThread.c:(.text+0x18): undefined reference to `pthread_create’
collect2: ld returned 1 exit status
make: *** [tone] Error 1
I get the same linker error for “servo” and “okLed”. It seems that the pthreads library is missing from the linker invocation. I’ve made the following modification to the Makefile to fix:
pi@raspberrypi ~/github/wiringPi/examples $ git diff -p Makefile
diff –git a/examples/Makefile b/examples/Makefile
index 738d36c..f219c9e 100644
— a/examples/Makefile
+++ b/examples/Makefile
@@ -95,15 +95,15 @@ serialRead: serialRead.o
okLed: okLed.o
@echo [link]
– @$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS)
+ @$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS) -lpthread
tone: tone.o
@echo [link]
– @$(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS)
+ @$(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS) -lpthread
servo: servo.o
@echo [link]
– @$(CC) -o $@ servo.o $(LDFLAGS) $(LDLIBS)
+ @$(CC) -o $@ servo.o $(LDFLAGS) $(LDLIBS) -lpthread
.c.o:
Oops – missed the same fix for wfi in the Makefile… Partial patch:
wfi: wfi.o
@echo [link]
– @$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS)
+ @$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS) -lpthread
Hi,
thanks for that. I goofed when I re-introduced the static libraries again. I have a fix for it, but not pushed it out to the GIT site yet. Will get there soon!
Cheers,
-Gordon
Trying the build on OS X 10.7.5.. getting this:
wiringPi Build script – please wait…
WiringPi library
[Compile] wiringPi.c
wiringPi.c:350:47: error: invalid suffix “b100” on integer constant
Really not used to C.. any thoughts?
Sorry, I left out important error messages. The ‘invalid suffix’ goes on for a while, and then I get:
wiringPi.c: In function ‘wiringPiSetup’:
wiringPi.c:1114: warning: cast from pointer to integer of different size
wiringPi.c:1115: warning: cast from pointer to integer of different size
..
..
which goes on for a while. And then:
make: *** [wiringPi.o] Error 1
[Install]
install: libwiringPi.a: No such file or directory
make: *** [install] Error 71
So I guess I’m just missing this file.. but where is it?
It’s probably a side-effect of the binary constands not being recognised earlier.
Can you build it directly on a Raspberry Pi?
-Gordon
It’s designed to be built on a Raspberry Pi. The 0b number prefix is relatively new extension to C, and might not be in the compiler you’re using on the Mac.
-Gordon
Ah. I suspected that it needed to be built on the Pi, but that was failing for me because I didn’t have the necessary tools installed. I’m very fresh on Arch Linux and I just learned about pacman.
Thanks for the tip. Getting some build errors but I’m much further along.
I do all my stuff under Raspbian – because I’ve been using Debian for 18+ years now, and it seems to be what everyone else is using on the Pi right now too.
Not sure what packages you might need under Arch to build it though – basic compiler & build tools I imagine, make, gcc, etc.
-Gordon
Success!
I had scp’d to the Pi the repo I cloned on my mac. That wasn’t working, so I installed git on the Pi, cloned WiringPi locally, and it built fine.
Onward..
Hi Gordon,
Does this error message tell you/us why git clone isn’t working for me? I don’t know if it is just me or if others are having the same problem.
thanks,
b
pi@raspberrypi ~ $ git clone git://git.drogon.net/wiringPi
Cloning into ‘wiringPi’…
fatal: unable to connect to git.drogon.net:
git.drogon.net[0: 195.10.226.169]: errno=Connection timed out
git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Address family not supported by protocol
I’m supecting that maybe your local site is blocking GIT for some reason. The server is running (check with https://git.drogon.net/ ) and I’ve just done some test GIT fetches from it.
There was an issue a few days ago with IPv6, but that should be sorted – and it looks like your site can’t do IPv6 anyway – which is what’s leading me to think it might be an issue at your end – maybe a firewall?
You can use the web link above to ge a tar.gz image of wiringPi (click on wiringPi in the main screen, then click on the ‘snapshot’ link at the right).
-Gordon
OK. Another reply – as it actually looks like it might have been *my* firewall this time. (oops!)
Give it another go and let me know how you get on.
Thanks,
-Gordon
Hi –
I’m having the same issue here. I can wget the package, but not git clone it – same error as the original poster. I know it is not our local firewall as I can control it :)…
Thanks
Wondering now if it’s to do with IPv6… You could try this:
git clone git://195.10.226.169/wiringPi
The wget package is old and will give you build issues with I2C (which I see from your other replies here)
-Gordon
yep that was it. Thanks.
Hi Gordon,
Something you might want to add to your instructions is to tell users that if they have trouble installing git to run the following command first. I am new to Linux and it took me a while to solve that problem.
sudo aptitude update
This is a heads up to some of the people having the no control of GPIO2 problem.
I just installed the newest archlinuxarm – and had the GPIO2 stuck low. I don’t remember if wiringpi was already installed – I think so. Arch’s pacman still has an older package. Anyway, removed the distro version and did a new build.
/usr/local/lib/ is not searched for libwiringPi.so.1.0
moved to /usr/lib/ and built the symlinks. Works fine.
I’ve been trying all day and have had trouble cloning from your git server:
root@mypi:/opt/wiringPi# git clone git://git.drogon.net/wiringPi
Cloning into ‘wiringPi’…
fatal: unable to connect to git.drogon.net:
git.drogon.net[0: 195.10.226.169]: errno=Connection timed out
git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Address family not supported by protocol
root@mypi:/opt/wiringPi#
[ha ha I have a dead beef cafe]
Am I doing something wrong or is your server somehow unavailable?
There were some issues a few days ago (mostly to do with ipv6 and firewalling), but I’m pretty sure they’re OK, and I can see people using the site OK now. Can you access https://git.drogon.net/ instead? Just do some basic network tests, ping, ping6, etc.
The same physical server runs this website, so the server itself is fine – just some issues with GIT maybe…
-Gordon
Aha problem fixed – firewall blocked TCP port 9418, which is needed by git protocol – the list is at . I unblocked 9418 and it worked.
Sorry, after submitting this issue, I see somebody else had a similar problem 4 messages up. I thought I checked for that before submitting a comment. Maybe my fix is helpful to them too…
[sent from my pi using IceWeasel browser…]
Gordon,
I am newish to linux and c, although I have programmed in other languages and windows for years. I want to transmit using an Ebay RF Wireless Transmitter and Receiver Link Kit Module 433Mhz for Remote Control on the Raspberry Pi and receive on an Arduino. I installed wiringPi using the instructions at the top of this page: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/ I can make test1 ok, however I want to compile the send.cpp program from this site: https://github.com/r10r/rcswitch-pi I copied send.cpp, RCSwitch.cpp and RCSwitch.h to /home/pi/wiringPi/wiringPi/examples (where test1.c is) and tried to compile using this command: g++ send.cpp -o send But I get these errors: send.cpp:(.text+0x58): undefined reference to `wiringPiSetup’
send.cpp:(.text+0x9c): undefined reference to `RCSwitch::RCSwitch()’
send.cpp:(.text+0xac): undefined reference to `RCSwitch::enableTransmit(int)’
I thought that I needed to compile RCSwitch first so I tried: g++ RCSwitch.cpp -o RCSwitch But got cant find ‘main’, which is understandable becuase it does not exist in RCSwitch.cpp
I think my knowledge of c and making of c programs is letting me down – Can you help, please?
Sorry if this is a bit basic, Chris.
You need to include the wiringPi library, so:
g++ -o send send.cpp -lwiringPi
However you also need to compile the library at the same time, so:
g++ -o send send.cpp RCSwitch.cpp -lwiringPi
Check the Makefile there too – that should have worked OK.
-Gordon
Gordon – thanks that worked a treat, but now I am having problems at run-time.
I decided to go back to basics and just try to flash a LED.
When I use the GPIO commands I can make my LED flash on then off
gpio mode 4 out
gpio write 4 1
gpio write 4 0
Then I wrote a small test program in c to do the same:
#include
#include
#include
#include
int main (void)
{
int pin;
int n;
printf (“Raspberry Pi wiringPi test1b program\n”) ;
if (wiringPiSetupSys() == -1)
exit (1) ;
pin = 4;
for( n=0; n<5; n++)
{
pinMode (pin, OUTPUT) ;
digitalWrite (pin, HIGH);
delay(1000);
digitalWrite (pin, LOW);
delay(1000);
}
printf ("Finished\n") ;
return 0 ;
}
The "make test1b" (in the examples folder), resulted in:
gcc -O3 -Wall -I/usr/local/include -Winline -pipe -L/usr/local/lib test1b.c -lwiringPi -o test1b
When I ran it:
./test1b
Raspberry Pi wiringPi test1b program
Finished
The LED did not flash – what am I doing wrong?
the issue is that the gpio command uses naive wiringPi pin numbers by default, and your using wiringPiSetupSys() in the code.
So if you change the wiringPiSetupSys() into wiringPiSetup() then it will work, but you’ll need to run the progam with sudo.
If you want to do it without sudo, then:
gpio export 23 out
and use the wiringPiSetupSys() in the program, and change pin 4 to pin 23.
However pinMode() does’t work in ‘Sys’ mode – it will only ever work if you use sudo. (And you only need to do it once, not in the loop)
-Gordon
Thanks for your speedy response.
I have recoded as suggested:
if (wiringPiSetup() == -1)
exit (1) ;
pin = 23; // == GPIO 4;
pinMode (pin, OUTPUT) ;
for( n=0; n<5; n++)
{
digitalWrite (pin, HIGH);
delay(1000);
digitalWrite (pin, LOW);
delay(1000);
}
I did the:
gpio export 23 out
But now my Pi just crashes when I run:
sudo ./test1b
I get no error message – it just hangs, all the lights go out on the Pi except one red led, the same one that remains lit when you do a shutdown.
it’s pin number confision.
bcm_gpio Pin 23 is wiringPi pin 4.
wiringPiSetup() – my own wiringPi pin numbers.
wiringPiSetupSys() – bcm_gpio pin numbers.
Stick to one system or the other.
So here, change the 23 into 4.
you don’t need the gpio export command in wiringPi() mode either.
And, as you’ve seen, poking the wrong pins can crash the pi!
-Gordon
Unable to build…any thoughts?
pi@raspberrypi ~/wiringPi $ ./build
wiringPi Build script – please wait…
WiringPi library
./build: line 28: cd: wiringPi: No such file or directory
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target `install’. Stop.
GPIO Utility
./build: line 33: cd: ../gpio: No such file or directory
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target `install’. Stop.
Examples
./build: line 38: cd: ../examples: No such file or directory
make: *** No targets specified and no makefile found. Stop.
All Done.
pi@raspberr
It really sounds like the installation is incomplete. Do you have the gpio, wiringPi and examples directories?
try this:
cd
rm -rf wiringPi
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
-Gordon
here is a print of the wiringPi directory….
pi@raspberrypi ~ $ sudo dir /home/pi/wiringPi
build COPYING.LESSER examples gpio People
pi@raspberrypi ~ $ sudo dir /home/pi/wiringPi/examples
COPYING.LESSER gertboard.png nes.c pwm.c servo.c test2.c
delayTest.c lcd.c okLed.c README.TXT speed.c tone.c
gertboard.c
Makefile piface.c serialRead.c test1.c wfi.c
pi@raspberrypi ~ $ sudo dir /home/pi/wiringPi/gpio
COPYING.LESSER gpio gpio.1 gpio.c gpio.o Makefile test.sh
Well it looks fine, but please stop using sudo for everything. That’s probably where it’s all gone wrong – the files will have been installed with root premissions rather than that of the ‘pi’ users (or whaterver user you are doing).
So… Best to start again..
cd
sudo rm -r wiringPi
…. then don’t use sudo, but:
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
not a sudo in sight.
-Gordon
Thanks for the help…but still no luck….
pi@raspberrypi ~ $ cd
pi@raspberrypi ~ $ sudo rm -r wiringPi
pi@raspberrypi ~ $ git clone git://git.drogon.net/wiringPi
Cloning into 'wiringPi'...
remote: Counting objects: 204, done.
remote: Compressing objects: 100% (204/204), done.
remote: Total 204 (delta 122), reused 0 (delta 0)
Receiving objects: 100% (204/204), 79.75 KiB, done.
Resolving deltas: 100% (122/122), done.
pi@raspberrypi ~ $ cd wiringPi
pi@raspberrypi ~/wiringPi $ ./build
wiringPi Build script - please wait...
WiringPi library
[Compile] wiringPi.c
[Compile] wiringPiFace.c
[Compile] wiringSerial.c
[Compile] wiringShift.c
[Compile] gertboard.c
[Compile] piNes.c
[Compile] lcd.c
[Compile] piHiPri.c
[Compile] piThread.c
[Compile] wiringPiSPI.c
[Compile] softPwm.c
[Compile] softServo.c
[Compile] softTone.c
[Link (Static)]
[Link (Dynamic)]
[Install]
GPIO Utility
[Compile] gpio.c
[Link]
[Install]
Examples
wiringPi Examples
=================
There are now too many examples to compile them all in a sensible time,
and you probably don't want to compile or run them all anyway, so they
have been separated out.
To compile an individual example, just type
make exampleName
Where exampleName is one of:
test1 test2 speed lcd wfi piface gertboard nes pwm tone servo
delayTest serialRead okLed
All Done.
pi@raspberrypi ~/wiringPi $ make test1
make: *** No rule to make target `test1'. Stop.
pi@raspberrypi ~/wiringPi $ make speed
make: *** No rule to make target `speed'. Stop.
pi@raspberrypi ~/wiringPi $ make lcd
make: *** No rule to make target `lcd'. Stop.
pi@raspberrypi ~/wiringPi $
You need to change into the examples directory first.
cd examples
make test1
and so on.
-Gordon
Hi,
I am facing a problem interfacing GPIO with the Hello_pi samples.
My objective is to seek videos from a switch connected to GPIO. I am using Hello video.c program (in directory /opt/vc/src/hello_pi) I have figured out how to seek videos but I am not able to get GPIO input in the hello video program. The problem lies in compiling the program which is by “make”command and running the hello_video.bin
I browsed through the messages above. But I did not see a mention on it.
So, could you please tell me if it’s possible by adding wiringPi.h?
Thanks,
IF you have installed wiringPi, then it should not be hard. You add
#include <wiringPi.h>
into your program, initialise and use wiringPi as per the examples programs, just remember to include
-lwiringPi
when linking the program
-Gordon
I did the exact same thing.
I tried it earlier with bcm2835.h too but it gives same problem. May be i’m doing something wrong. Just correct me if I am wrong.
1. I copied and saved test1.c program to /home/pi
2. On terminal screen I wrote “gcc test1.c -lwiringPi”
It shows
“usr/bin/ld: cannot find lwiringPi
collect2:ld returned 1 exit status ”
also when I compile hello video program in which I use digitalRead and pinMode to take input ;
by “make -lwiringPi”
It gives warning as
“implicit declaration of function ‘pinMode’ ‘digitalRead’ and also error with ‘wiringPi setup’
Are you sure you typied it correctly? There is a hyphen (or a minus sign) in-front of the lwiringPi, so:
cc -o test1 test1.c -lwiringPi
For hello_video, you will probably have to edit the Makefile to include the -lwiringPi. Look in the Makefile:
Change:
LDFLAGS+=-lilclient
into
LDFLAGS+=-lilclient -lwiringPi
If you still get undefined references then it means that you have probably not installed wiringPi correctly.
-Gordon
WOWOWOW!!
THanks so much. the edit in makefile was the culprit!
This means a lot to me. I had been banging my head all this weekend. if you would been around I would have given a treat to you !
😀
Sir, you Rock!
Gordon,
I follow the instruction according the link below.
Keep getting error: cp: cannot stat `gpio’: No such file or directory
I can’t find any file in /usr/local/bin/ as mention in post above.
I do not work under sudo as mention in post above.
Any suggestion ??
Ruud.
Link:
https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/
//Part of screendump:
collect2: ld returned 1 exit status
make: *** [gpio] Error 1
[Install]
cp: cannot stat `gpio’: No such file or directory
make: *** [install] Error 1
Examples
I can’t tell what’s going on without more clues, however if there were references to some smbus/i2c earlier on the build run, then you managed to fetch a version of wiringPi that was live for about 10 miuntes before I added another check into it – re-fetch it and try it again.
look at the start of the gpio.c program to check – if the version is 1.7 then it’s the newest and there is something else wrong, if it’s anything other than 1.7 then fetch the new version…
-Gordon
Hi,
I just ran into the same error. The test for existence of /usr/include/linux/i2c-dev.h does not work correctly. On my Raspbian with libi2c-dev not installed the file exists, because it is provided by linux-libc-dev. After I installed it, compilation worked fine.
With libi2c-dev installed:
root@pi:~# dpkg -S /usr/include/linux/i2c-dev.h
diversion by libi2c-dev from: /usr/include/linux/i2c-dev.h
diversion by libi2c-dev to: /usr/include/linux/i2c-dev.h.kernel
linux-libc-dev:armhf, libi2c-dev: /usr/include/linux/i2c-dev.h
And without:
root@pi:~# dpkg -S /usr/include/linux/i2c-dev.h
linux-libc-dev:armhf: /usr/include/linux/i2c-dev.h
I’m not sure how to fix it, because checking if the package is installed would only work on debian-based systems.
Armin
Yes, thanks. I’ll work another way as I’ve had a couple of issues with that now. One way might even be to take out the I2C code for now.
-Gordon
Think I can fix it by grepping for the right functions in the overlaid version of i2c-dev.h.
Still can’t auto-install the package, but at least I can provide a pointer!
-Grodon
I’m confused. I’m having this issue too. I have /usr/include/linux/i2c-dev.h but I’m getting:
usr/lib/gcc/arm-linux… ‘i2c_smbus_write_byte’
‘i2c_smbus_read_byte’
_write_byte_date’ …
collect2: ld returned 1 exit status
make: *** [gpio] Error 1
[Install]
cp: cannot stat `gpio’: No such file or directory
make: *** [install] Error 1
What issue too?
Sorry – this isn’t really a forum so the comments don’t thread well, so I’m a little confused about what you’re getting.
Firstly, have you got the latest version of wiringPi (Not the one from the project-downloads site, but the one via GIT). If you did not use GIT to download it, then you will not have the latest wiringPi and the compile will fail unless you install the i2c-dev package – and note that you will have a /usr/include/linux/i2c-dev.h, but not the right one!
So – sudo apt-get install libi2c-dev
will fix that for you – unless you’re on Arch in which case you won’t get the I2C stuff at all as they don’t provide it yet.
-Gordon
Problem solved.
Start from scratch new .img on sd-card.
Follow the instruction.
Get a error and message to install I2C lib.
After that ./build runs oke.
Thanks
Thanks Gordon,
I’m very new to using the Raspberry pi. How do I go about installing this libi2c-dev without the internet connected to my raspberry pi?
Thanks
How did you get wiringPi into the Pi without Internet?
You really need an Internet connection – you need to update & upgrade the existing software on the Pi from the initial SD card image. The nyou can fetch the i2c stuff and the latest wiringPi, etc.
-Gordon
I downloaded the wiringPi folder onto a usb stick and copied it into my home directory… i compiled the makefile for wiringPi ok but not the makefile for the gpio…. hmmm
If you can still use a usb stick to do the transfer then:
Fetch the latest wiringPi – use git if possible.
Fetch this file: http://unicorn.drogon.net/i2c-dev.h
copy the i2c-dev.h file to /usr/include/linux/i2c-dev.h
make wiringPi:
cd wiringPi
./build
Do not try to use the inidvidual makefiles.
-Gordon
thanks for your help
I had wiringPi working on Raspbmc, but I had to create a new version of Raspbmc and now I cannot get wiringPi to work again.
It installed fine.
pi@raspbmc:~/wiringPi$ ./build
wiringPi Build script – please wait…
WiringPi library
[UnInstall]
[Compile] wiringPi.c
[Compile] wiringPiFace.c
[Compile] wiringSerial.c
[Compile] wiringShift.c
[Compile] gertboard.c
[Compile] piNes.c
[Compile] lcd.c
[Compile] piHiPri.c
[Compile] piThread.c
[Compile] wiringPiSPI.c
[Compile] wiringPiI2C.c
[Compile] softPwm.c
[Compile] softServo.c
[Compile] softTone.c
[Link (Dynamic)]
[Install]
GPIO Utility
[Compile] gpio.c
[Link]
[Install]
Examples
wiringPi Examples
=================
There are now too many examples to compile them all in a sensible time,
and you probably don’t want to compile or run them all anyway, so they
have been separated out.
To compile an individual example, just type
make exampleName
Where exampleName is one of:
test1 test2 speed lcd wfi isr piface gertboard nes pwm tone servo
delayTest serialRead serialTest okLed
All Done.
But when I run my script to initialise the necessary pins to drive my binary clock I get an error message.
Here is my script
#! /bin/bash
sudo ntpdate 0.uk.pool.ntp.org
pins=(“2 3 4 14 15 17 18 27 22 23”)
#initialise the pins for output and set all pins to 0
for x in $pins
do
gpio -g mode $x out
gpio -g write $x 0
done
gpio -g mode 24 in
And here are the error messages
pi@raspbmc:~/scripts$ ./settime.sh
17 Jan 12:57:28 ntpdate[1163]: the NTP socket is in use, exiting
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
gpio: Unable to initialise GPIO mode.
I have tried running the script with sudo but I get the same errors. Any ideas?
thanks
Struggling to work out why not, however can you do this: Add this line to your script:
export WIRINGPI_DEBUG=1
at the top, before the gpio lines and run it – email me the output if you want as it’s a bit verbose for here…
-Gordon
Ps. ntpdate can’t be run once ntp has started, it used to be common to run ntpdate befoew ntp, but if ntp is started with the right flags, it’s not needed anymore…
Hi,
I update via git today and can confirm that the problems are now solved in raspbmc.
Thanks for your help.
Luke
Thanks!
-Gordon
Great guide Gordon.
Followed all of the above and seems to work fine.
However before building it gave me this message: The wiringPi I2C helper libraries will not be built.
Is this OK or has it errored in some way?
Thanks,
Simon
Perfectly normal and in some-ways I’m glad you got that message 😉
I’ve had a bit of a struggle to make sure other peoples system can build wiringPi – when they don’t have the i2c development libraries installed – essentially, I’ve put together some “helpers” for I2C similar to what I did for SPI, but it seems the I2C systems are widly different on different distributions. My I2C code is still somewhat experimental though, but if you are running Raspbian, then:
sudo apt-get install libi2c-dev
then re-doing the ./build ought to build and install them OK.
-Gordon
Problems compiling…
The library compiles up OK, but when I try to use it to compile gpio or any of the examples, I get a set of error messages of the type
libwiringPi.so: undefined reference ‘i2c_smbus_read_byte’
… and then again for several other i2c functions.
I’ve done an ‘apt-get update’ but no luck. The package was downloaded via wget (as git gives me errors connecting) and is the Jan 15 version. I’ve also installed the libi2c-dev as you mention above, but this has not helped either. The error message sounds like another library needs to be linked?
Thanks,
Steve
… and solved.
I noticed the problem was that the functions were set as inline in linux/i2c-dev.h — seems that make had helpfully decided not to recreate wiringPiI2C.o after I installed the libi2c-dev and so the old .o still held them as external references. Removed all .o files and ran build again, and all was fine.
Thanks for making this available!
-Steve
sudo apt-get intstall libi2c-dev
will work under Raspbian, but I updated the GIT version to cope with this for now. (changed the Makefile to not include i2c)
If you can’t use GIT, then fetch the GTI version via http:
Go here: https://git.drogon.net/?p=wiringPi;a=summary
and select the snapshot link on the right…
-Gordon
Can’t build my C-project in Code::Block with wiringPi:
————– Build: Debug in LS020 —————
Compiling: main.c
Compiling: ../../wiringPi/wiringPi/wiringPi.c
/home/pi/wiringPi/wiringPi/wiringPi.c: In function ‘delay’:
/home/pi/wiringPi/wiringPi/wiringPi.c:1054:19: error: storage size of ‘sleeper’ isn’t known
/home/pi/wiringPi/wiringPi/wiringPi.c:1054:28: error: storage size of ‘dummy’ isn’t known
/home/pi/wiringPi/wiringPi/wiringPi.c:1059:3: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
/home/pi/wiringPi/wiringPi/wiringPi.c:1054:28: warning: unused variable ‘dummy’ [-Wunused-variable]
/home/pi/wiringPi/wiringPi/wiringPi.c:1054:19: warning: unused variable ‘sleeper’ [-Wunused-variable]
/home/pi/wiringPi/wiringPi/wiringPi.c: In function ‘delayMicrosecondsSys’:
/home/pi/wiringPi/wiringPi/wiringPi.c:1083:19: error: storage size of ‘sleeper’ isn’t known
/home/pi/wiringPi/wiringPi/wiringPi.c:1083:28: error: storage size of ‘dummy’ isn’t known
/home/pi/wiringPi/wiringPi/wiringPi.c:1083:28: warning: unused variable ‘dummy’ [-Wunused-variable]
/home/pi/wiringPi/wiringPi/wiringPi.c:1083:19: warning: unused variable ‘sleeper’ [-Wunused-variable]
/home/pi/wiringPi/wiringPi/wiringPi.c: In function ‘delayMicrosecondsHard’:
/home/pi/wiringPi/wiringPi/wiringPi.c:1108:3: warning: implicit declaration of function ‘timeradd’ [-Wimplicit-function-declaration]
/home/pi/wiringPi/wiringPi/wiringPi.c:1110:3: warning: implicit declaration of function ‘timercmp’ [-Wimplicit-function-declaration]
/home/pi/wiringPi/wiringPi/wiringPi.c:1110:34: error: expected expression before ‘<’ token
/home/pi/wiringPi/wiringPi/wiringPi.c: In function ‘delayMicrosecondsWPi’:
/home/pi/wiringPi/wiringPi/wiringPi.c:1117:19: error: storage size of ‘sleeper’ isn’t known
/home/pi/wiringPi/wiringPi/wiringPi.c:1117:19: warning: unused variable ‘sleeper’ [-Wunused-variable]
Process terminated with status 1 (0 minutes, 4 seconds)
6 errors, 8 warnings
I’ve no idea what Code::Blocks is, but it looks like it’s trying to build wiringPi rather than use wiringPi’s own build system.
Why are you not building wiringPi as a library and linking with the library? That’s the way I’ve designed it to work.
Those error messages indicate that a header file is missing, or has not been included. Probably time.h or sys/time.h.
-Gordon
IDE Code::Blocks from http://store.raspberrypi.com/projects/codeblocks.
I don’t understand how to connect the library, simple insert headers does not work.
Sorry. I’ve no idea. It’s not something I’ve ever used.
Normally I’d suggest building the library standalone, and installing it, then working out how to include the header file in your program (if a simple #include <wiringPi.h> doesn’t work, then work out how to make code::blocks include the library at program link time. you need to get it to include -lwiringPi
-Gordon
Connected to linker file libwiringPi.so.1.0.
Project builded, but displays:
wiringPi:
Must be root to call wiringPiSetup().
(Did you forget sudo?)
Yes, that’s right. You need to be root to call wiringPiSetup(). Did you forget to use sudo ?
-Gordon
Thanks for the effort first of all. I am a bit stuck. I want to connect to a wii nunchuck. With the following :
i2cdetect -y 1
i2cput -y 1 0x52 0x40
i2cput -y 1 0x52 0x00
i2cdump -y -r 0-5 1 0x52 c
I get values.
With you utilities, I tried:
…
// is this correct, from you document I think it should be 1???
// but then where do you give the device address?
wiringPiI2CSetup(0x52);
fd = open(“/dev/i2c-1”, O_RDWR)
wiringPiI2CWrite(fd, 0x40);
wiringPiI2CWrite(fd, 0x00);
Then in a for loop
byte = wiringPiI2CWrite(fd);
…
But it doesn’t seem to work. Could you, or some other knowledgeable being, please help me out. I noticed there were no example using your i2c functions.
Thanks,
I don’t know how the Wii nunchucks worok, however:
If the device is 0x52, then you just need to do:
fd = wiringPiI2CSetup (0x52) ;
then to write 0x40 to the device:
wiringPiI2CWrite (fd, 0x40) ;
This is a simple write one byte down the bus command. If you’re writing to a device register, then use:
wiringPiI2CWriteByte8 (fd, 0x40, value) ;
I think the mistake you might be making is calling open() rather than use the return value from wiringPiI2CSetup()
-Gordon
Thanks for the tip. that solved the first issue. But for some reason I don’t think the next two are equal.
i2cdump -y -r 0-5 1 0×52 c
for (int i = 0; i < 6; i++) {
array[1] = wiringPiI2CRead(fd);
}
Is the read with or without an ACK.
This is what I need. Is you code able to handle reads with/without the ACK bit set?
for(i=0;i<5;i++) //5 values with ACK
{
data[i]= read_Ack();
}
data[5]= read_Nak(); // the last one without
Thanks,
Some I2C devices can simply supply data in response to read requsts, some need you to read a particular register. You’ll need to study the device to see how.
My routines are nothing more than easy to use wrappers round the standard Linux libraries, so AIUI, they all handle ACK, START, etc. stuff just returning the data to you.
So if you need to read a register, then use wiringPiI2CReadReg8 (or readReg16), but if the device just sends bytes, then a simple wiringPiI2CRead will work. I have a touchscreen that does the latter – it sends 5 bytes at a time, so I do 5 back to back wiringPiI2CRead () calls and it works just fine.
It’s also possible that I don’t know what I’m doing, but that works for the limited number of devices I have used so-far.
i2cdump reads registers sequentially. To emulate that, use
for (i = 0 ; i < 6 ; ++i) array [i] = wiringPiI2CReadReg8 (fd, i) ; to read registers 0-5 inclusive. -Gordon
Hi Gordon,
From all reports wiringPi is an excellent piece of work allowing us novices to get projects off the ground (mine is home automation which I plan to use the Pi as a web server).
I am having trouble installing wiringPi, I am sure that I am doing something stupid so I have included the output from Pi, I dont need i2c, just gpio interfaces to C.
Output:-
pi@raspberrypi ~ $ cd /tmp
pi@raspberrypi /tmp $ wget http://project-downloads.drogon.net/files/wiringPi.tgz –2013-02-07 08:56:44– http://project-downloads.drogon.net/files/wiringPi.tgz
Resolving project-downloads.drogon.net (project-downloads.drogon.net)… 195.10.22 6.169, 2a00:ce0:2:feed:beef:cafe:0:4
Connecting to project-downloads.drogon.net (project-downloads.drogon.net)|195.10.2 26.169|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 335974 (328K) [application/x-gzip]
Saving to: `wiringPi.tgz’
100%[========================================>] 335,974 104K/s in 3.2s
2013-02-07 08:56:48 (104 KB/s) – `wiringPi.tgz’ saved [335974/335974]
pi@raspberrypi /tmp $ dir
wiringPi.tgz
pi@raspberrypi /tmp $ tar xfz wiringPi.tgz
pi@raspberrypi /tmp $ dir
wiringPi wiringPi.tgz
pi@raspberrypi /tmp $ cd wiringPi/wiringPi
pi@raspberrypi /tmp/wiringPi/wiringPi $ make
[Compile] wiringPi.c
[Compile] wiringPiFace.c
[Compile] wiringSerial.c
[Compile] wiringShift.c
[Compile] gertboard.c
[Compile] piNes.c
[Compile] lcd.c
[Compile] piHiPri.c
[Compile] piThread.c
[Compile] wiringPiSPI.c
[Compile] wiringPiI2C.c
wiringPiI2C.c: In function âwiringPiI2CReadâ:
wiringPiI2C.c:43:3: warning: implicit declaration of function âi2c_smbus_read_byteâ [-Wimplicit-function-declaration]
wiringPiI2C.c: In function âwiringPiI2CReadReg8â:
wiringPiI2C.c:55:3: warning: implicit declaration of function âi2c_smbus_read_byte_dataâ [-Wimplicit-function-declaration]
wiringPiI2C.c: In function âwiringPiI2CReadReg16â:
wiringPiI2C.c:60:3: warning: implicit declaration of function âi2c_smbus_read_word_dataâ [-Wimplicit-function-declaration]
wiringPiI2C.c: In function âwiringPiI2CWriteâ:
wiringPiI2C.c:72:3: warning: implicit declaration of function âi2c_smbus_write_byteâ [-Wimplicit-function-declaration]
wiringPiI2C.c: In function âwiringPiI2CWriteReg8â:
wiringPiI2C.c:84:3: warning: implicit declaration of function âi2c_smbus_write_byte_dataâ [-Wimplicit-function-declaration]
wiringPiI2C.c: In function âwiringPiI2CWriteReg16â:
wiringPiI2C.c:89:3: warning: implicit declaration of function âi2c_smbus_write_word_dataâ [-Wimplicit-function-declaration]
[Compile] softPwm.c
[Compile] softServo.c
[Compile] softTone.c
[Link (Dynamic)]
pi@raspberrypi /tmp/wiringPi/wiringPi $ sudo make install
[Install]
pi@raspberrypi /tmp/wiringPi/wiringPi $ cd ../gpio
pi@raspberrypi /tmp/wiringPi/gpio $ make
[Compile] gpio.c
[Link]
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_byte’
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_byte’
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_byte_data’
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_word_data’
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_word_data’
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_byte_data’
collect2: ld returned 1 exit status
make: *** [gpio] Error 1
pi@raspberrypi /tmp/wiringPi/gpio $ sudo make install
[Install]
cp: cannot stat `gpio’: No such file or directory
make: *** [install] Error 1
pi@raspberrypi /tmp/wiringPi/gpio $
sorry for long winded output
Hoping you can help!
cheers,
Peter
Is there any reason you can’t use GIT?
the tgz version there is a little older than the GIT hosted version and doesn’t build on systems that don’t have the I2C helpers.
If you have git then:
cd
# rm -rf wiringPi # in-case you have an old one
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
Test with:
gpio -v
If you really can’t use GIT, then get the GIT version by going here:
https://git.drogon.net/?p=wiringPi;a=summary
and clicking on the snapshot link at the top-right.
-Gordon
Hi Gordon,
Looks like my router doesn’t like git:// so i downloaded as suggested put it in /tmp then:
pi@raspberrypi /tmp $ ls
wiringPi-56c77b5.tar.gz
pi@raspberrypi /tmp $ ./build
-bash: ./build: No such file or directory
what an I doing?
or should I follow the previos route?
thanks,
Peter
Soundsl ike you’re there, but just in-case
tar xfz wiringPi-56c77b5.tar.gz
cd wiringPi-56c77b5
./build
-Gordon
Hi Gordon,
Thanks a lot I am getting there!
Thanks to your help test1 works!
Thanks,
peter
Gordon,
Just a note to say the WiringPi i2c module works fine on Arch Linux, with a minor hack! All the necessary kernel modules are present in Arch, it’s just the Arch i2c-dev.h header that’s incompatible.
Steps needed are:
1) Update Arch.
# pacman -Syu
# uname -r
3.6.11-6-ARCH+
2) Install api-headers and i2c-tools.
# pacman -Sy linux-api-headers i2c-tools
3) Hack: get the Debian i2c-dev.h header file (http://unicorn.drogon.net/i2c-dev.h) or extract from the Raspbian distro.
3) Install the Debian header in place of the Arch one.
# mv /usr/include/linux/i2c-dev.h /usr/include/linux/i2c-dev.h.saved
# cp /i2c-dev.h /usr/include/linux/i2c-dev.h
4) Build WiringPi.
# cd ~/wiringPi
# ./build
The i2c module should then build and install just fine.
5) Remove and reload the i2c kernel modules, using a lower baud rate.
# rmmod i2c_bcm2708 i2c_dev
# gpio load i2c 10
The lower baud rate (10Kbps) was needed to get my i2c ADC working. Maybe other devices would accept a higher rate (trail & error).
The WiringPi i2c functions then work well on Arch. In my case, I also needed to read block data from the ADC, which I could do with the ‘i2c_smbus_read_i2c_block_data()’ native function.
I prefer Arch, so it’s nice to know the wiringPi i2c module works with the above tweak!
Many thanks,
Dave
Thanks for that!
-Gordon
i’m having difficulties compiling this with cross-compile toochain, is it even possible ? Cos I’m developing on my main linux machine not on raspberry.
I’ve no idea. I’m sure some are x-compiling though. I do all my Pi work directly on a Pi.
-Gordon
I had the same problems as Peter Davis. I had trouble connecting to the git.drogon.net site, maybe a firewall problem, so I used the ‘wget’ method and followed your instructions. I got warnings in compiling wiringPi and couldn’t link gpio.
You do not mention running ‘build’ in the above install instructions but, after looking through ‘build’, I loaded the I2C development libraries and, so far, the problems have gone away.
Thanks for sharing you work, I am looking forward to using your tools and having fun.
John Windle
The other method will get you an older version of wiringPi. To get the latest, then use the GIT site via http…
Access the GIT site using https://git.drogon.net/
Navigate to the project – e.g. wiringPi, then look on the right-hand side where you will see a link marked “snapshot”. Download this and unpack it – it will create a filename like wiringPi-123456789abvdef.tar.gz and extract into a directory like wiringPi-1234567879abcdef.
-Gordon
Do the Download and Install instructions require the V2 board. I have the V1 board but both the new and old methods fail.
It should download on either board OK – or do you mean compile/build? (in which case it should still do that OK on either board).
Let me know what sort of error messages you’re getting
-Gordon
first To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi
my results
Cloning into ‘wiringPi’…
fatal: unable to connect to git.drogon.net:
git.drogon.net[0: 195.10.226.169]: errno=Connection refused
git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Address family not supported by protocol
Phil
I’ve just checked and have no issues downloading from a variety of different sites, so I suspect you may have a local firewall issue.
If you go here:
https://git.drogon.net/?p=wiringPi;a=summary
and click on the top-right link marked “snapshot” then it will download a tar.gz file which you can unpack and install as before.
-Gordon
Gracias Gordon!!
Great stuff! Works awesome!
Could you add this to the library; because there are some compatibility issues around the booleans.
typedef bool boolean;
C doesn’t have a native bool type. Only C++
So as I write in C, if I did that then it would make it incompable with C.
However I’ll double check to make sure the I’m not using bool/boolean anywhere that might conflict with c++
-Gordon